

const {ccclass, property} = cc._decorator;

@ccclass
export default class RotateAnim extends cc.Component {


    @property({displayName: "动画类型"})
    animType: number = 0;

    start () {
        switch (this.animType) {
            case 1:
                this.rotateAnim();
                break;
            case 2:
                this.circle();
                break;
        }

    }
    //动画
    anim(){
        this.node.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.rotateTo(0.3, 30),
                    cc.rotateTo(0.3, 0),
                    cc.rotateTo(0.3, -30),
                    cc.rotateTo(0.3, 0),
                )
            )
        )
    }

    scaleAnim(){
        this.node.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.scaleTo(0.3, 1.2),
                    cc.scaleTo(0.3, 1)
                )
            )
        )
    }

    rotateAnim(){
        cc.tween(this.node)
            .repeatForever(
                cc.tween()
                    .to(0.07, {angle: -15})
                    .to(0.07, {angle: 0})
                    .to(0.07, {angle: 15})
                    .to(0.07, {angle: 0})
                    .to(0.07, {angle: -15})
                    .to(0.07, {angle: 0})
                    .to(0.07, {angle: 15})
                    .to(0.07, {angle: 0})
                    .delay(1.5)
            )
            .start()
    }

    circle(){
        cc.tween(this.node)
            .repeatForever(
                cc.tween()
                    .by(3.5, {angle: 360})
            )
            .start()
    }

    // update (dt) {}
}
